package com.xxx.video.dynamic.adapters;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.xxx.video.R;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.adapters.BaseViewHolder;
import com.xxx.video.dynamic.beans.FriendListBean;

import java.util.List;

import butterknife.BindView;

public class RecommendFriendAdapter extends BaseRecycleViewAdapter<FriendListBean.PageBean.ListBean, RecommendFriendAdapter.MyHolder> {
    private List<FriendListBean.PageBean.ListBean> list;

    public RecommendFriendAdapter(@NonNull Context context) {
        super(context);
    }

    @Override
    public MyHolder onCreateDefaultViewHolder(View view, int viewType) {
        return new MyHolder(view);
    }

    @Override
    public int getItemLayout(int viewType) {
        return R.layout.item_recommend_friend;
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    @Override
    public boolean isSetBaseItemViewClickListener() {
        return false;
    }

    public void setFriendListData(List<FriendListBean.PageBean.ListBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public void addFriendSuccess(int position) {
        list.get(position).fStatus = "0";
        notifyDataSetChanged();
    }

    class MyHolder extends BaseViewHolder {


        @BindView(R.id.tv_item_recommend_friend_title)
        TextView tvItemRecommendFriendTitle;
        @BindView(R.id.tv_item_recommend_friend_more)
        TextView tvItemRecommendFriendMore;
        @BindView(R.id.rcv_item_recommend_friend_list)
        RecyclerView rcvItemRecommendFriendList;

        public MyHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setData2View(int position) {
            rcvItemRecommendFriendList.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
            RecommendFriendHorizontalListAdapter recommendFriendHorizontalListAdapter = new RecommendFriendHorizontalListAdapter(context);
            rcvItemRecommendFriendList.setAdapter(recommendFriendHorizontalListAdapter);
            recommendFriendHorizontalListAdapter.setData(list);
            tvItemRecommendFriendMore.setOnClickListener(v -> {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(null, position, 1);
                }
            });
            recommendFriendHorizontalListAdapter.setOnItemClickListener((OnItemClickListener<FriendListBean.PageBean.ListBean>) (listBean, position1, type) -> {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(listBean, position1, type);
                }
            });
        }
    }
}
